//
//  TJAdViewController.m
//  Teleport
//
//  Created by botu　 on 2020/8/1.
//  Copyright © 2020 byx. All rights reserved.
//

#import "TJAdHomeController.h"
#import "JXCategoryView.h"
#import "TJAdController.h"
#import "TJAdListController.h"
@interface TJAdHomeController ()<JXCategoryViewDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *categoryView;


@property (strong, nonatomic) UIScrollView *mainView;

@end

@implementation TJAdHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *titles = @[@"购买广告".localizedString, @"出售广告".localizedString];
      
        JXCategoryIndicatorLineView *indicatorLineView = [[JXCategoryIndicatorLineView alloc] init];
       indicatorLineView.indicatorHeight = 2;
       indicatorLineView.indicatorColor = UIColor.tj_mainColor;
       indicatorLineView.verticalMargin = 0;
    
      self.navigationBar.lineView.hidden = YES;
      self.categoryView.titles = titles;
        self.categoryView.titleFont = RegularFont(14);
      self.categoryView.titleColor = UIColor_Hex(0x262626);
      self.categoryView.titleSelectedColor =UIColor.tj_mainColor;
      self.categoryView.selectedAnimationEnabled = YES;
      self.categoryView.delegate = self;
      self.categoryView.titleLabelZoomEnabled = YES;
      self.categoryView.titleColorGradientEnabled = YES;
      self.categoryView.frame = CGRectMake(0 ,0, 200, 44);
        self.categoryView.indicators = @[indicatorLineView];
    self.navigationBar.titleView = self.categoryView;
    
    
      self.mainView = [UIScrollView tj_addToView:self.view];
      self.mainView.frame = CGRectMake(0, KNavBarHight, KScreenWidth, KScreenHeight);
      self.mainView.pagingEnabled = YES;
      self.mainView.delegate = self;
      self.mainView.bounces = NO;
      self.mainView.contentSize = CGSizeMake(self.mainView.frame.size.width * titles.count, self.mainView.frame.size.height);
      self.mainView.showsHorizontalScrollIndicator = NO;
      self.mainView.showsVerticalScrollIndicator = NO;
     // [self.view addSubview:self.categoryView];
      
      self.categoryView.defaultSelectedIndex = 0;
      //加子控制器
      TJAdController *buyControntroller = [[TJAdController alloc] init];
      buyControntroller.navigationBar.hidden = YES;
      buyControntroller.type = 0;
      buyControntroller.view.frame = CGRectMake(0, 0, self.mainView.tj_width, self.mainView.tj_height);
      [self addChildViewController:buyControntroller];
      [self.mainView addSubview:buyControntroller.view];
    
      
      TJAdController *sellControntroller = [[TJAdController alloc] init];
      sellControntroller.type = 1;
      sellControntroller.navigationBar.hidden = YES;
      sellControntroller.view.frame = CGRectMake(KScreenWidth, 0, self.mainView.tj_width, self.mainView.tj_height);
      [self addChildViewController:sellControntroller];
      [self.mainView addSubview:sellControntroller.view];
    
    self.navigationBar.rightBarButton = [TJButtonBarButton barButtonWithImageName:@"ad_list_btn" target:self action:@selector(didClickRightButton)];
}
- (void)didClickRightButton{
    TJAdListController *vc = [TJAdListController new];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self.categoryView selectItemAtIndex:scrollView.contentOffset.x / KScreenWidth];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    

    [self.mainView setContentOffset:CGPointMake(self.mainView.tj_width * index, 0) animated:YES];
}


- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[JXCategoryTitleView alloc] init];
    }
    return _categoryView;
}

@end
